Raspberry Pi 4 can be booted by PXE boot. You can either make the entire file system on the remote server or just make the boot partition remote.
In this article, we choose the latter since we will mostly only update the kernel of the Raspberry Pi.
Prerequisites
Raspberry Pi configuration
EEPROM Configuration
Raspberry Pi 4, 400 and Compute Module 4 computers use an EEPROM to boot the system.
To enable PXE boot, you should first modify the EEPROM configuration.
sudo apt install rpi-eeprom
rpi-eeprom-config --edit
Then modify/add the following entries:
[all]
BOOT_UART=1
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
BOOT_ORDER=0xf412
TFTP_IP=PXE_SERVER_IP
The BOOT_ORDER option decides the boot order of the RPi4. It will be decided by from the least significant byte to higher ordered bytes.
For example, 0x2 means boot from NETWORK, 0x1 means boot from SD CARD and 0x4 means boot from USB. So 0xf412 above specifies the boot order of NETWORK->SD CARD->USB. 0xf means reboot if all previous boot mode fail.
Replace PXE_SERVER_IP with the IP address of your PXE server.
Copy the boot partition of your RPi to your PXE server
The boot partition of the RPi locates at /boot/firmware. You should copy the entire directory to your PXE server.
Note Down the Serial Number of Your RPI
RPI uses its serial number to locate the boot partition on the PXE server. To get the serial number, run
cat /proc/cpuinfo | grep Serial | awk -F ': ' '{print $2}' | tail -c 8
Note down the serial number. It will be used later.
GRACEFULLY SHUTDOWN YOUR RPI with shutdown now or halt -p so the changes are written to the EEPROM.
PXE Server Configuration
TFTP Server Configuration
On your PXE server, install tftpd-hpa TFTP server:
sudo apt install tftpd-hpa
Then configure the server
vi /etc/default/tftpd-hpa
You should configure the TFTP server with the following option
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
Create the Boot Partition for the RPI
As we mentioned above, the RPI looks up the boot partition on the PXE server using its serial number. You should create a directory using the serial number of your RPI as the name in the tftp root directory and copy all the files in the boot partition into it.
mkdir -p /srv/tftp/RPI_SERIAL
cp -a firmware/* /srv/tftp/RPI_SERIAL
Now you can test your TFTP server on another client in the network by:
tftp PXE_SERVER_IP
> get RPI_SERIAL/cmdline.txt
If you have the cmdline.txt downloaded, you are one step away from getting your RPI network booted.
Boot Your Raspberry Pi
Simply boot your RPi with a ethernet cable plugged in. You should see the following output from your serial console:
ARP PXE_SERVER_IP PXE_SERVER_MAC
NET RPI_IP_ADDRESS 255.255.255.0 gw 0.0.0.0 tftp PXE_SERVER_IP
RX: 26 IP: 0 IPV4: 30 MAC: 2 UDP: 2 UDP RECV: 2 IP_CSUM_ERR: 0 UDP_CSUM_ERR: 0
TFTP_GET: PXE_SERVER_MAC PEX_SERVER_IP RPI_SERIAL/start4.elf
You are now boot your RPI from the Network.